import * as types from '../action-types';
export default {
	login(user) {
		//https://github.com/reduxjs/redux-thunk/blob/master/src/index.js
		return function (dispatch,getState,request) {
			//http://localhost:4000/api/users
			return request.post('/api/login',user).then(result => {
				console.log(result)
				dispatch({
					type: types.SET_SESSION,
					payload:result.data.data
				});
			});
		}
	},
	logout() {
		//https://github.com/reduxjs/redux-thunk/blob/master/src/index.js
		return function (dispatch,getState,request) {
			//http://localhost:4000/api/users
			return request.get('/api/logout').then(result => {
				dispatch({
					type: types.SET_SESSION,
					payload:result.data
				});
			});
		}
	},
	getUser() {
		return function (dispatch,getState,request) {
			//http://localhost:4000/api/users
			return request.get('/api/user').then(result => {
				dispatch({
					type: types.SET_SESSION,
					payload:result.data.data
				});
			});
		}
	}
}